package com.youbug.system.controller;


import com.youbug.common.vo.QueryVo;
import com.youbug.system.entity.Article;
import com.youbug.system.service.IArticleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章管理 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2024-03-03
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
@Autowired
private IArticleService articleService;

    @PostMapping("/getArticlePage")
    public R<IPage<Article>> getArticlePage(@RequestBody QueryVo<Article> queryVo){

        IPage<Article> articles = articleService.getArticlePage(queryVo);

        return R.ok(articles);
    }

    @GetMapping("/getArticleById/{id}")
    public R<Article> getMenusForRole(@PathVariable Integer id){

        Article article = articleService.getById(id);

        return R.ok(article);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Article article){

        boolean save = articleService.save(article);

        return  R.ok(save);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Article article){

        boolean update = articleService.updateById(article);

        return  R.ok(update);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Integer id){

        boolean remove = articleService.removeById(id);

        return  R.ok(remove);
    }
}

